package com.example.simple3;
import android.content.Context;
import android.content.Intent;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.simple3.*;

import android.app.Activity;

import android.view.View;

import android.os.Bundle;

import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;
 
public  class main2 extends Activity {
	//ArrayList<infoclass>data;
	ListView list;
	//SimpleCursorAdapter adapter=null;
	SQLiteDatabase db;
	simple mHelper;
	String str,str2;
	String str3[];
	//InputMethodManager sm;
	Cursor cursor;
	Intent i;
	 final static String dbName = "simple3.db";
	 final static int dbVersion = 2;
	@Override
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main3);
	  
	LinearLayout LL;
	LL=(LinearLayout)findViewById(R.id.l_layout);
		
	//data=new ArrayList<infoclass>();
	list=(ListView)findViewById(R.id.listView1);
	mHelper=new simple(this);
	
	
	//db=mhelp.getReadableDatabase();
	selectDB();
	
	//adapter=new ArrayAdapter<infoclass>(this, android.R.layout.simple_list_item_1,data);
	//sm=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
	
	//cursor=db.rawQuery("select m.no,menu,mtext,m.meno from simple_m m inner join simple_menu menu where m.meno=menu.no and m.meno=0;", null);
	//startManagingCursor(cursor);
	//adapter=new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,new String[]{"mtext"},new int[]{android.R.id.text1});
	
	//list.setAdapter(adapter);
	list.setOnItemClickListener(new OnItemClickListener(){

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position,
				long arg3) {
			// TODO Auto-generated method stub
		try{

				cursor.moveToPosition(position);
				str=new String(cursor.getString(cursor.getColumnIndex("mtext")));
				str2=new String(cursor.getString(cursor.getColumnIndex("image")));
                str3[0]=str;
                str3[1]=str2;
				i=new Intent(getApplicationContext(),result.class);		
                i.putExtra("value",str3[0]);		
                i.putExtra("value",str3[1]);		
                
                startActivity(i);
               
		}
               catch(Exception e){
            	   
               }
			}
		});
	}
		
	
	




	private void selectDB(){
			 
		  //try{
		  db=mHelper.getReadableDatabase();
		  str="select  menu._id,menu,mtext,m.meno,image from simple_m m inner join simple_menu menu where m.meno=menu._id and m.meno=1;";
		  str2="select  menu._id,menu,mtext,m.meno,image from simple_m m inner join simple_menu menu where m.meno=menu._id and m.meno=1;";
					
				
			  //  db=mhelp.getReadableDatabase();
		cursor=db.rawQuery(str, null);
		cursor=db.rawQuery(str2, null);
		if(cursor.getCount()>0){
			startManagingCursor(cursor);
			custom dbAd=new custom(this,cursor);
			list.setAdapter(dbAd);
		} 
		
		//}
		//catch(SQLException e){
		//}
		
			
			
	}	
	
}